package com.xhj.xmly.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xhj.xmly.R;
import com.xhj.xmly.bean.Radio;

import java.util.List;
import java.util.Locale;

/**
 * Created by Administrator on 2016/12/5.
 */

public class BroadcastAdapter extends RecyclerView.Adapter<BroadcastAdapter.ViewHolder>{
    private Context context;
    private List<Radio> list;

    public BroadcastAdapter(Context context, List<Radio> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.broadcast_item,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText(list.get(position).getName());
        holder.subname.setText("正在直播： "+list.get(position).getProgramName());

        holder.playcount.setText(String.format(Locale.getDefault(),"%.1f万人 ",list.get(position).getPlayCount()/10000.0));
        Picasso.with(context).load(list.get(position).getCoverSmall()).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView,icon;
        private TextView textView,subname,playcount;
        public ViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.broadcast_image);
            icon = (ImageView) itemView.findViewById(R.id.broadcast_icon);
            textView = (TextView) itemView.findViewById(R.id.broadcast_name);
            subname = (TextView) itemView.findViewById(R.id.broadcast_subname);
            playcount = (TextView) itemView.findViewById(R.id.broadcast_num);
        }
    }
}
